package com.jiang.sign.Config;

import com.jiang.sign.Dao.LoginUser;
import org.springframework.context.annotation.Bean;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
/*
* 自定义权限
* */

@Component
public class RootAuthor {

   // @Bean    //注入进去 直接@方法名字就好了
    public boolean hasAuthorityWithJiang(String authority){
        //获取当前用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissionList();
        //判断用户权限集合中是否存在authority
        return permissions.contains(authority);
    }
}
